package org.peterf.foxish.scene;

import java.util.LinkedList;

import org.peterf.foxish.camera.Camera;
import org.peterf.foxish.component.Presentable;
import org.peterf.foxish.engine.Engine;

public class SequentScene extends Scene {

    private LinkedList<Presentable> presentableList = new LinkedList<Presentable>();
    
    private boolean created = false;

    public SequentScene(Engine engine) {
        super(engine);
    }

    public void postPresentable(Presentable p) {
        if (created || state != SceneState.INIT) {
            p.onCreate();
        }
        presentableList.addLast(p);
    }
    
    public void prePresentable(Presentable p) {
        if (created || state != SceneState.INIT) {
            p.onCreate();
        }
        presentableList.addFirst(p);
    }
    
    public void insertPresentable(int location, Presentable p) {
        if (created || state != SceneState.INIT) {
            p.onCreate();
        }
        presentableList.add(location, p);
    }

    @Override
    public void onCreate() {
        for (Presentable p : presentableList) {
            p.onCreate();
        }
        created = true;
    }

    @Override
    public void onDestroy() {
        for (Presentable p : presentableList) {
            p.onDestroy();
        }
    }

    @Override
    public void onDraw(Camera camera, float elapsed) {
        for (Presentable p : presentableList) {
            p.onDraw(camera, elapsed);
        }
    }

    @Override
    public void onRecreate() {
        for (Presentable p : presentableList) {
            p.onRecreate();
        }
    }

    @Override
    public void onRestored() {
        // TODO
    }

    @Override
    public void onStored() {
        // TODO
    }

}
